home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 32 (1993-02)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 32 (1993-02)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / hyperbook / HB_Macros < prev    next >
Text File  |  1993-02-11  |  17KB  |  351 lines

  1.                
  2.                                               
  3.                      M a c r o s   i n        
  4.                                                    by John Collett
  5.                      H y p e r B o o k        
  6.                                               
  7.     
  8.     
  9.      Do it in RAM: 
  10.  
  11.     This package is in three parts :
  12.     
  13.       (a) The HyperBook 'HBReader' program.
  14.       (b) A hyperbook unit called 'defaulthyperbook'. When you click on 
  15.           the 'HBReader' icon, this unit is automatically selected.
  16.       (c) This article, 'HB_Macros', for which it is assumed that FullView
  17.           is available.
  18.     
  19.     They should all be in the same directory.  If, for a really smooth
  20.     performance, you decide to run this presentation in Ram:, then move
  21.     the whole of the current drawer, as it stands.    
  22.  
  23.      Purposes of this presentation 
  24.     
  25.     1  To acknowledge the quality of HyperBook.
  26.     
  27.     2  To show off, briefly, a few of its main features, for readers who
  28.     haven't yet seen it in action.
  29.  
  30.     3  To mention the remarkable HyperBook Macro Language (HML) which comes
  31.     as an added bonus with HyperBook.
  32.     
  33.     4  To go a little deeper into the topic of ARexx macros in Hyperbook,
  34.     and to provide examples of the kind of thing they can do.
  35.  
  36.     5  To explain how the article itself serves as raw material for some
  37.     of the macros we shall be discussing.
  38.  
  39.     6  To show how another program can be run from within HyperBook. 
  40.     FullView could be used to display this text, and access to it could
  41.     be via the HyperBook unit.
  42.  
  43.     
  44.      Introduction 
  45.     
  46.     Except at startup, I rarely see my WorkBench or a CLI window nowadays. 
  47.     No, I haven't got DirOpus; I have HyperBook, which sets up a tailor-
  48.     made working environment for me. Everything I need is readily
  49.     available, and that environment is easy to modify.
  50.  
  51.     It is often the case with commercial packages that once you are using
  52.     them you are in a straight-jacket designed by the authors, and you keep
  53.     saying "If only it would let me do this!" or "Why can't I do that?" I
  54.     haven't had that feeling with HyperBook, in which I find I can do most
  55.     of the things I ever wanted to do or tried to do in a traditional
  56.     programming language, and can do many of them more easily.   
  57.  
  58.     There has been and still is some learning to be done, of course, but
  59.     the manual is well-written and the disks are full of examples.
  60.     Literally within minutes you can have your first own hyperbook up and
  61.     running. You can easily cross the magic threshold into ARexx (assuming
  62.     you have it), and then you can start to explore the excellent built-in
  63.     HyperBook Macro Language. Before long you will have unlocked the
  64.     treasure chest of macros, exploring the examples supplied, and moving
  65.     into the more challenging area of writing and using your own.
  66.     
  67.     Perhaps the clearest way I can express my satisfaction with HyperBook
  68.     is to say that I have both AmigaVision and CanDo, but don't use either
  69.     of them.
  70.  
  71.      HyperBook Macro Language 
  72.     
  73.     From the manual:
  74.     
  75.      ---------------------------------------------------------------------
  76.     |        HyperBook         "a general purpose multi-media tool that   |
  77.     |        (page 1)           lets you store and organize text and      |
  78.     |                           graphics in any format."                  |
  79.     |                                                                     |
  80.     |    HyperBook + ARexx     "to offer you additional capabilities."    |
  81.     |       (page 109)                                                    |
  82.     |                                                                     |
  83.     | HyperBook + ARexx + HML  "let's you create 'intelligent'            |
  84.     |       (page 109)          applications of almost                    |
  85.     |                           unlimited flexibility."                   |
  86.      ---------------------------------------------------------------------
  87.     
  88.     HML is a collection of 130 or so ready-made macros, an extremely useful
  89.     addition to your programming tools, facilitating work in various areas
  90.     under the following headings:
  91.  
  92.       HyperBook control   |  Page editing         |   Searches           
  93.       Navigation          |  Object creation      |   User input         
  94.       Main control panel  |  Object editing       |   Text editing       
  95.       General editing     |  Actions              |   Printing           
  96.       Page creation       |  Note and button text |   Data display       
  97.       Master pages        |  Items and lists      |   Language support   
  98.       Page files          |                       |
  99.  
  100.     The HyperBook Samples disk contains a large hyperbook tutorial
  101.     called ARexx.hb which demonstrates and explains all the HML functions. 
  102.     The disk also contains various other HyperBook goodies such as an
  103.     AddressBook, AppointmentsBook, Calendar and Calculator.
  104.  
  105.     It was immediately obvious that the best way to learn how all the
  106.     functions behave was to use them.  So I wrote my own sequence of
  107.     'pages', systematically using practically every one of the 130
  108.     functions, from 'num = NUMPAGES()' (manual page 117) to 'value =
  109.     RAND(low, high) on page 131.  When I got stuck (one or two misprints in
  110.     the manual, or I was having a bad day), I consulted ARexx.hb to see how
  111.     the masters had done it, and all was well. The authors do in fact
  112.     advise that procedure, and acknowledge that the manual is less accurate
  113.     than the tutorial program. 
  114.  
  115.     Then it was time to use what I had learned in something more
  116.     challenging.
  117.  
  118.      The Macro Samples on the Samples Disk 
  119.    
  120.       Samples: macros      
  121.         Bevel{obj}                       CenterObject
  122.         ExecuteText                      FileToList{fname}
  123.         FileToNote{fname}                GetObjSize
  124.         ListCurrentPage                  SaveListText{list,fname}
  125.         SaveNoteText{note,fname}         SavePageColors
  126.         SetItemActions                   SetObjSize
  127.         StdColorSet                      
  128.          sample (dir)
  129.           ActionInfo                       ChangeNoteNames
  130.           CloneItem                        CloneThisPage
  131.           TextRange{fname,first,nlines}
  132.     
  133.     The five macros in the separate 'sample' directory, are described (p.140)
  134.     as 'some less general examples'. 
  135.     
  136.     Braces, {} not (), are used to indicate the type and number of
  137.     arguments which need to be passed when some of these macros are called,
  138.     braces being needed to make the entries legal in the above list.  But
  139.     when they are used, then the standard form of brackets are required. 
  140.     In fact the macro editor makes the change for you.
  141.  
  142.     Exploring these macros was easy, but my insights needed sharpening, and
  143.     my memory needed a prop.  In the process, I used one or two of the
  144.     provided macros as well as constructing some of my own :
  145.  
  146.     1 To obtain the above directory listing from the Samples disk and
  147.       convert it into a HyperBook 'List'.
  148.  
  149.     2 To set 'actions' for each member of that list, so that a click on
  150.       any of them would :
  151.     
  152.        (a) Obtain the few lines of explanatory comment from the
  153.            head of the relevant file.
  154.        (b) Convert that piece of text into a HyperBook 'Note',
  155.            and tidy up its format.
  156.        (c) Position and size the note according to the length 
  157.            of text it was to contain.
  158.     
  159.     This all worked astonishingly well, and I decided to share the pleasure
  160.     with my one or two regular MegaDisc readers.  The reduced form of
  161.     HyperBook, the 'HBReader', would be fine for the presentation, but other
  162.     logistic matters were less easy to solve.  It would be out of the
  163.     question to include all the macros just to demonstrate how a part of
  164.     each one could be extracted and presented as a note. So I decided
  165.     instead to use the text of this article as source material for similar
  166.     if not identical macro demos.
  167.     
  168.     Introductory Demos
  169.                                                       Its macro  
  170.           #1  Sample 'objects' and 'actions'          ListJobs
  171.           #2  A look-alike of the full HB menu        ShowMenu
  172.     
  173.     Demos using the Article
  174.     
  175.           #3  Information on the article              FileInfo
  176.           #4a Making a list of subheadings            SubHeadings
  177.             b Setting a 'readpatch' action
  178.           #5  Converting tables to 'Lists'            Table
  179.           #6  Building a 'Note'                       SecretMessage
  180.  
  181.      Introductory Demos 
  182.     
  183.       #1 Sample 'objects' and 'actions' 
  184.     
  185.     If you've got ARexx, explore all the objects you see on the first demo
  186.     'page' by clicking on them. Except for the List, their actions have
  187.     been set by ARexx commands.  In the List, click on each of its items.
  188.     Their actions are dealt with by a single macro I've called ListJobs,
  189.     which makes use of the following HML functions:
  190.  
  191.           Initiator()      GetLeft()        ShadowStyle()   
  192.           Inform()         GetTop()         SetBorder()     
  193.           GetName()        SetPosition()    SetShadow()     
  194.           ReadNoteText()   GetWidth()       ShadowStyle()   
  195.           DeleteText()     GetHeight()      GetItemText()   
  196.           InsertText()     Scale()          SetItemText()   
  197.  
  198.  
  199.       #2 A look-alike of the full HB menu 
  200.  
  201.     It's a reasonable imitation of the real thing, though of course none of
  202.     the items work, and it shows none of the sub-menus.  When each menu
  203.     header is clicked, a small macro toggles 'off' any other menu list
  204.     which may have just been looked at.
  205.  
  206.      Demos using the Article 
  207.  
  208.       #3 Information on the article 
  209.         
  210.        To confirm that the article exists, and provide related information.
  211.     
  212.     Main steps in macro :
  213.     
  214.     1 Is 'rexxsupport.library' active?  If not, use 'addlib()'.
  215.     2 Successful?
  216.       (a) If so, then :
  217.             Call 'statef()' and parse the result
  218.             Assemble 'text' as required  
  219.             Set position and size variables for new 'Note'
  220.       (b) If not, use DOS instead of ARexx :
  221.             address command 'list >ram:temp article_file_name'
  222.             Load 'ram:temp' into 'text'.
  223.             Set position and size 
  224.     3 Create a new 'Note', insert the text, scale it to size, set it 
  225.       in position, set its name, and relocate it from the 'bin' where
  226.       it is created to the required page - all done by HML commands
  227.       carrying the appropriate arguments.
  228.  
  229.         
  230.       #4a A list of subheadings 
  231.     
  232.        To extract and build into a 'List' all the article subheadings.
  233.  
  234.     In fact demos #4a and #4b use the same macro, but its work will be
  235.     described in two stages.
  236.     
  237.     Main steps in macro :
  238.  
  239.     1 Use a DOS search command ('address command etc.') to find all lines
  240.       in the source file which carry the colour coding for a subheading.
  241.       Store the output in a temporary file.
  242.     2 Create a new 'List', small, empty, in the 'bin'.
  243.     3 Open the temporary file, read in each line, strip off the colour
  244.       codings, and append each line as an 'item' in the 'list'. 
  245.     4 At eof, leave the loop, close the file, and delete it.
  246.     5 Scale the list to size, set it in position, set its name, and 
  247.       relocate it.
  248.     
  249.     (On reflection, that temporary file is probably not necessary - instead,
  250.     put item 2 first, then find, strip, and append each subheading - but it
  251.     seemed like a good idea at the time.)
  252.  
  253.     The list of subheadings is then in place. How to make use of it is
  254.     described under Demo #4b.
  255.      
  256.       #4b Setting a 'readpatch' action 
  257.  
  258.        To set an 'action' for each item in the Demo #4a list, to
  259.        display the patch of text which comes under the particular
  260.        subheading.
  261.     
  262.     The patches are too long to be 'Notes', and so HyperBook's text reader
  263.     is used to present them.  HyperBook contains its own text editor and
  264.     text reader.  Both of them are surprisingly good for such features
  265.     included as part of a larger package, and both pleasant to handle. The
  266.     reader handles ANSI colours in a slightly different way from FullView,
  267.     and such codings in this article are not quite the same as I usually
  268.     use for a MegaDisc article, so that the text will appear in reasonable
  269.     shape either via FullView or via the HB text reader.
  270.  
  271.     While I have tried to keep all these demo macros as 'dynamic' as
  272.     possible, that is, have them do their complete job when they are
  273.     called, I decided to cheat a bit on this one, to avoid having to
  274.     include a sizeable HyperBook utility called 'TextRange'.
  275.     
  276.     When the HML function 'ShowTextRange' is called to screen a patch of a
  277.     file, it needs to know how many bytes into the file the required patch
  278.     starts, and how many bytes are to be screened. This sort of information
  279.     is not immediately available, but can be obtained by supplying the
  280.     TextRange utility with the number of the first line and the number of
  281.     lines to be included - information which is easy to obtain.  I have
  282.     used TextRange in advance, and the values required for ShowTextRange
  283.     are stored in an invisible list called 'Bytes' on the page concerned.
  284.  
  285.     Main steps in macro :
  286.   
  287.     1 Confirm object numbers for lists called 'Bytes' and 'SubHeadings'
  288.       using SearchName().
  289.  
  290.     2 Loop through all the elements in the 'Subheadings' list :
  291.     
  292.     (a) Obtain the 'start' and 'amount' values from the corresponding
  293.         entry in 'Bytes'.
  294.     (b) Set the 'action' for the 'Subheadings' item to 'ShowTextRange',
  295.         with the 'start' and 'amount' just obtained.
  296.       
  297.       #5 Converting tables to 'Lists' 
  298.     
  299.       To extract a table from the article, and format it into a 'List', 
  300.       but with no further 'actions', since I have to stop somewhere.
  301.  
  302.     One example is enough for this demonstration and I decided to use the
  303.     table of HML topics which you may have seen about six screens ago. I do
  304.     not want just to screen the text as was done in Demo #4b, so
  305.     ShowTextRange is not needed. Instead, I use ARexx 'seek' to find the
  306.     starting point in the article, and then the 'readln()' function to read
  307.     in the few lines needed.
  308.  
  309.     Like ShowTextRange, 'seek' needs to know the number of bytes, and so
  310.     once again I used the ShowRange utility, in advance, to obtain that
  311.     value.
  312.  
  313.     Main steps in macro :
  314.     
  315.     1  Open the source file.
  316.     2  Go to the required point using 'seek'.
  317.     3  Create a new and empty 'List'.
  318.     3  Read in lines from the source table until an empty line is reached.
  319.     4  Divide each line at '|' to create a single column.
  320.     5  Append each part-line as an 'item' in the 'list'.
  321.     6  Scale the list to size, set it in position, set its name, and 
  322.        relocate it.
  323.  
  324.  
  325.       #6 Building a 'Note' 
  326.     
  327.     There is an invisible message here (text in the background colour!).
  328.     Demo #6 will find it and display it in a 'Note', using steps similar to
  329.     those in Demo #5.  Colours, frame, font, style, text spacing, line
  330.     spacing, formatting, etc. are all handled automatically in the process.
  331.  
  332.    .I hereby acknowledge with respect and   
  333.    .gratitude the superb work done by       
  334.    .Chris Zamara and Nick Sullivan,         
  335.    .the authors not only of HyperBook,      
  336.    .but also of 'Using ARexx on the Amiga'. 
  337.    .                                        
  338.    .     Great stuff, you guys!             
  339.     
  340.     This is the only source of the text of the message which you will see.
  341.     It could have been hidden in a ready-made but invisible 'Note', made
  342.     visible when you ask to see it, but that would not have shown the
  343.     process of constructing a note from separate source material.
  344.     
  345.     
  346.      Hamilton, NZ, November, 1992
  347.  
  348.                 =========================================
  349.  
  350.  
  351.